
<?php
require_once './model/page_db.php';
$query = "SELECT * FROM pages LIMIT 0,20";
$data = getFilms($query);
$key = NULL;
$max = NULL;
$min = NULL;
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="public/css/style_mysql1.css" type="text/css">
<form method="POST">
    <div id="tt">

        <strong> Keyword :</strong> <input type="text" name="key"></br>
        <strong>     Minnfans :</strong> <input type="text" name="min"></br>
        <strong>   Maxfans :</strong> <input type="text" name="max">
        <strong>  <input type="submit" name="submit" value="Search"></strong>
    </div>
</form>

<?php if (isset($_POST['submit'])): ?>
    <?php $key = (String) $_POST['key']; ?>
    <?php $min = (double) $_POST['min']; ?>
    <?php $max = (double) $_POST['max']; ?>
<?php endif; ?>


<table id="bang1">
    <tr class="dong1">
        <th class="pid">  pid  </th>
        <th class="id">  id </th>
        <th class="name">  likes </th>
        <th class="username">  picture </th>
        <th class="phone"> username </th>
        <th class="likes">  description </th>
    </tr>
    <?php foreach ($data as $datas): ?>
    <?php if (empty($key)): ?>
        <?php if (empty($min) && empty($max)): ?>
            <tr class="dong2">
                <td class="pid"><?php echo $datas["pid"] ?>  </td>       
                <td class="likes"><?php echo $datas["id"] ?>  </td>
                <td class="id"><?php echo $datas["likes"] ?>  </td>       
                <td class="phone"><img src="<?php echo $datas["picture"] ?>">  </td>
                <td class="username"><?php echo $datas["username"] ?>  </td>
                <td class="name"><?php echo $datas["description"] ?>  </td>    
            </tr>


        <?php elseif (empty($max)): ?>
            <?php if ($min <= (double) $datas['likes']): ?>
                <tr class="dong2">
                    <td class="pid"><?php echo $datas["pid"] ?>  </td>       
                    <td class="likes"><?php echo $datas["likes"] ?>  </td>
                    <td class="id"><?php echo $datas["id"] ?>  </td>       
                    <td class="phone"><img src="<?php echo $datas["picture"] ?>">  </td>
                    <td class="username"><?php echo $datas["username"] ?>  </td>
                    <td class="name"><?php echo $datas["description"] ?>  </td>    
                </tr>
            <?php endif; ?>

        <?php else: ?>
            <?php if ($min <= (double) $datas['likes'] && $max >= $datas['likes']): ?>
                <tr class="dong2">
                    <td class="pid"><?php echo $datas["pid"] ?>  </td>       
                    <td class="likes"><?php echo $datas["likes"] ?>  </td>
                    <td class="id"><?php echo $datas["id"] ?>  </td>       
                    <td class="phone"><img src="<?php echo $datas["picture"] ?>">  </td>
                    <td class="username"><?php echo $datas["username"] ?>  </td>
                    <td class="name"><?php echo $datas["description"] ?>  </td>    
                </tr>
            <?php endif; ?>
        <?php endif; ?>            
                <?php else: ?>
                <?php if (strstr($key, $datas['description'])) ?>
        <?php if ( empty($min) && empty($max)): ?>
            <tr class="dong2">
                <td class="pid"><?php echo $datas["pid"] ?>  </td>       
                <td class="likes"><?php echo $datas["id"] ?>  </td>
                <td class="id"><?php echo $datas["likes"] ?>  </td>       
                <td class="phone"><img src="<?php echo $datas["picture"] ?>">  </td>
                <td class="username"><?php echo $datas["username"] ?>  </td>
                <td class="name"><?php echo $datas["description"] ?>  </td>    
            </tr>


        <?php elseif (empty($max)): ?>
            <?php if ($min <= (double) $datas['likes']): ?>
                <tr class="dong2">
                    <td class="pid"><?php echo $datas["pid"] ?>  </td>       
                    <td class="likes"><?php echo $datas["likes"] ?>  </td>
                    <td class="id"><?php echo $datas["id"] ?>  </td>       
                    <td class="phone"><img src="<?php echo $datas["picture"] ?>">  </td>
                    <td class="username"><?php echo $datas["username"] ?>  </td>
                    <td class="name"><?php echo $datas["description"] ?>  </td>    
                </tr>
            <?php endif; ?>

        <?php else: ?>
            <?php if ($min <= (double) $datas['likes'] && $max >= $datas['likes']): ?>
                <tr class="dong2">
                    <td class="pid"><?php echo $datas["pid"] ?>  </td>       
                    <td class="likes"><?php echo $datas["likes"] ?>  </td>
                    <td class="id"><?php echo $datas["id"] ?>  </td>       
                    <td class="phone"><img src="<?php echo $datas["picture"] ?>">  </td>
                    <td class="username"><?php echo $datas["username"] ?>  </td>
                    <td class="name"><?php echo $datas["description"] ?>  </td>    
                </tr>
            <?php endif; ?>
        <?php endif; ?>
            <?php endif; ?>
    <?php endforeach; ?>
</table>